#include <func.h>
void *func(void *p)
{
    printf("child thread: time testing...\n");
    time_t t;
    time(&t);
    char buffer[128] = {0};
    char *ptime = ctime_r(&t,buffer);
    //char *ptime = ctime(&t);
    printf("child thread: before sleep value of ptime: %p, addr of ptime:%p\n",ptime,&ptime);
    printf("child thread: before sleep time: %s",ptime);
    printf("child thread: before sleep buffer: %s",buffer);
    sleep(3);

    printf("child thread: after sleep value of ptime: %p, addr of ptime:%p\n",ptime,&ptime);
    printf("child thread: after sleep time: %s",ptime);
    printf("child thread: after sleep buffer: %s",buffer);
}
int main(int argc,char **argv)
{
    pthread_t pthid;
    int ret = pthread_create(&pthid,NULL,func,NULL);
    THREAD_ERROR_CHECK(ret,"pthread_create");
    printf("main thread: pthread_create done, sleeping...\n");
    sleep(3);

    printf("main thread: wake up, time testing.\n");
    time_t t;
    time(&t);
    
    char buffer[128] = {0};
    char *ptime = ctime_r(&t,buffer);
    //char *ptime = ctime(&t);
    printf("main thread: value of ptime: %p, addr of ptime:%p\n",ptime,&ptime);
    printf("main thread: time now: %s\n",ptime);

    long thRet;
    ret = pthread_join(pthid,(void**)&thRet);
    THREAD_ERROR_CHECK(ret,"join");
    printf("child exti code:%ld",thRet);

    
    return 0;
}

